export default {
    date(value, exp = 'yyyy/MM/dd HH:mm:ss') {
        function fillZero(number, length) {
            return new Array(length - String(number).length + 1).join('0') + number;
        }
        if ((value = new Date(value)).valueOf()) {
            var y = value.getFullYear().toString(),
                M = value.getMonth() + 1,
                d = value.getDate(),
                w = value.getDay(),
                H = value.getHours(),
                h = H > 12 ? H - 12 : H,
                t = H < 12 ? 'AM' : 'PM',
                m = value.getMinutes(),
                s = value.getSeconds(),
                ms = value.getMilliseconds();
            return exp
                .replace(/yyyy/, y)
                .replace(/yy/, y.substring(2))
                .replace(/MM/, fillZero(M, 2))
                .replace(/M/, M)
                .replace(/dd/, fillZero(d, 2))
                .replace(/d/, d)
                .replace(/w/, w)
                .replace(/W/, ['日', '一', '二', '三', '四', '五', '六'][w])
                .replace(/HH/, fillZero(H, 2))
                .replace(/H/, H)
                .replace(/hh/, fillZero(h, 2))
                .replace(/h/, h)
                .replace(/t/, t)
                .replace(/T/, { AM: '上', PM: '下' }[t])
                .replace(/zms/, ms)
                .replace(/ms/, fillZero(ms, 3))
                .replace(/mm/, fillZero(m, 2))
                .replace(/m/, m)
                .replace(/ss/, fillZero(s, 2))
                .replace(/s/, s);
        }
    }
}